package com.example.util.mq.disruptor;

import com.alibaba.fastjson.JSON;
import com.example.util.TempWhiteListUtil;
import com.example.util.model.GwBusiProtocol;
import com.example.util.mq.disruptor.service.CspServiceFactory;
import com.example.util.mq.disruptor.service.MsgCommonService;
import com.lmax.disruptor.EventHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.File;


@Slf4j
@Component
public class DisruptorEventHandler implements EventHandler<MessageModel> {

    @Override
    public void onEvent(MessageModel event, long sequence, boolean endOfBatch) {
        log.info("【disruptor-mq】消费者处理消息开始,消费者消费的信息是：{}", event);
        if (event == null) {
            return;
        }
        try {

            FileReqData fileReqData = JSON.parseObject(event.getMessage(), FileReqData.class);
            GwBusiProtocol gwBusiProtocolByCode = GwBusiProtocol.getGwBusiProtocolByCode(fileReqData.getBusiType());
            MsgCommonService opCspService = CspServiceFactory.getOpCspService(gwBusiProtocolByCode, MsgCommonService.class);
            opCspService.doingBusi(fileReqData);

        } catch (Exception e) {
            log.error("【disruptor-mq】消费者处理消息失败_" + e.getMessage(), e);
        }
    }
}